package Annotation;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@RunWith(SpringJUnit4ClassRunner.class)
//加载spring核心配置文件
//@ContextConfiguration(value = {"classpath:applicationContext.xml"})
//加载spring核心配置类
@ContextConfiguration(classes = {SpringConfiguration.class})
public class SOtest {
    @Test
    public void testAnnoConfiguration() throws Exception {
        ApplicationContext applicationContext = new
                AnnotationConfigApplicationContext(SpringConfiguration.class); //使用新的注解开发加载class文件

        //新注解
        DataSource dataSource = (DataSource)applicationContext.getBean("dataSource");
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
    }

    @Autowired
    private DataSource dataSource;
    @Test
    public void test02() throws SQLException {
        System.out.println(dataSource.getConnection());
    }
}
